/** 
  A D 2.0 unit test framework inspired by Ruby's Unit::Test

// Written in the D programming language 1.0 || 2.0

Authors:	Wei Li (oldrev@gmail.com)
License:	BSD
Copyright:	Copyright (C) 2007 by Wei Li.
*/

module dotmars.test.runner;

import dotmars.io.console;
import dotmars.test.core;

static class ConsoleRunner
{
	static void showFailures(TestResult tr)
	{
		foreach(fail; tr.failures)
		{
			Console.printLine("Failure: {0}", fail.message);
			Console.printLine("{0} [{1}]", fail.testName, fail.location);
			Console.newLine();
		}
	}

	static void showErrors(TestResult tr)
	{
		foreach(err; tr.errors) 
		{
			Console.printLine("Error: {0}", err.exception.msg);
			Console.printLine("{0} [{0}]", err.testName, err.location);
			Console.newLine();
		}
	}

	static TestResult run(TestBase tb) 
	{
		auto result = new TestResult;
		Console.printLine("Started...");
		tb.run(result);
		Console.printLine("Finished\n");
		showErrors(result);
		showFailures(result);
		Console.newLine();
		Console.printLine("{0} tests, {1} assertions, {2} failures, {3} errors", 
			result.testCount, result.assertionCount, result.failureCount, result.errorCount);
		if(result.hasPassed)
			Console.printLine("All passed.");
		return result;
	}
}

